package com.ctesi.service.zhaobiao.hunan;

import org.springframework.stereotype.Service;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.Random;
@Service
public class ZhangJiaJieProcessorService implements PageProcessor {

    private String bidType;
    private Site site;
    @Override
    public void process(Page page) {
        Random random = new Random();
        // 生成5000到10000之间的随机整数
        int randomTime = random.nextInt(10000 - 5000 + 1) + 5000;

        //设置请求头和等待时间
        this.site = Site.me()
                .setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
                .setTimeOut(randomTime) // 设置超时时间为5秒到10秒之间的数
                .setRetryTimes(5); // 设置重试次数为 3 次
        site.addHeader("Connection", "keep-alive");

        String currentUrl = page.getUrl().get();
        if (currentUrl.contains("queryContent")){
            //裂变url执行逻辑

        }else {
            //爬取内容逻辑

            //招标主体信息

            //招标人信息

            //代理机构信息
        }
    }

    @Override
    public Site getSite() {
        return PageProcessor.super.getSite();
    }
}
